#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author   : zhongxin
# @Time     : 2022/9/2 11:56
# @File     : validates.py
# @Project  : PyCharm
from rest_framework import serializers

from product.models import Product


def whether_existed_product_id(value):
    """
    检查产品id是否存在
    :param value:
    :return:
    """
    if value != 0:
        if not isinstance(value, int):
            raise serializers.ValidationError('所选产品信息有误!')
        elif not Product.objects.filter(is_delete=False, id=value).exists():
            raise serializers.ValidationError('所选产品信息不存在!')
